package com.twang.stock.design.impl;

import com.alibaba.fastjson.JSONObject;
import com.twang.stock.design.IndexDataTask;
import com.twang.stock.dto.IndexedInfo;
import com.twang.stock.entity.DfcfBnakKuai;
import com.twang.stock.redis.RedisUtil;
import com.twang.stock.task.QueryBanKuaiAndDaPan;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.concurrent.CountDownLatch;

/**
 * 获取今日板块涨幅排行
 */
@Slf4j
@Service
public class DfcfBnakKuaisTask  extends IndexedInfo implements IndexDataTask {
    public static String cache_key = "DfcfBnakKuaisTask";

    @Autowired
    private RedisUtil redisUtil;
    @Override
    public void execute(ModelAndView modelAndView, CountDownLatch latch) throws Exception {
        try {
            List<DfcfBnakKuai> dfcfBnakKuais;
            //查询
            Object obj = redisUtil.get(cache_key);
            if (null == obj) {
                dfcfBnakKuais = QueryBanKuaiAndDaPan.geBKZF("");
            } else {
                dfcfBnakKuais = JSONObject.parseArray(obj.toString(), DfcfBnakKuai.class);
            }
            modelAndView.addObject("dfcfBnakKuais", dfcfBnakKuais);
            log.info("概念板块 ={} ", JSONObject.toJSONString(dfcfBnakKuais));

            setBankKaiTask(JSONObject.toJSONString(dfcfBnakKuais));
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            log.info("今日板块涨幅排行 执行完成，当前剩余条数:{}", latch.getCount());
            latch.countDown();
        }
    }
}

